package objects;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import map.Item;
import map.Lightmap;
import tools.Coordinate;

public class Player extends CombatEntity implements Serializable {
	

	private static final long serialVersionUID = 7594277767117814004L;
	private Coordinate coord;
	private String name;
	private int userId;
	private boolean ready;
	private int experience;
	private int maxExperience;
	private int percentExperience;
	private int level;
	private int sightRadius;
	private int curLevelIndex;
	private int spriteIndex;
	
	private List<Item> listItems;
	
	private Item itemWeapon;
	private Item itemShield;
	private Item itemHelmet;
	private Item itemArmor;
	
	
	
	public Player(Coordinate coord, String name, int userId, int spriteIndex) {
		super(100,0,10,10);
		this.level = 1;
		this.listItems = new LinkedList<Item>();
		this.coord = coord;
		this.name = name;
		this.userId = userId;
		this.experience = 0;
		this.sightRadius = 5;
		this.curLevelIndex = 0;
		this.spriteIndex = spriteIndex;
		this.percentExperience = 0;
		calcMaxExperience();
		
	}
	
	private void calcPercentExperience() {
		this.percentExperience = this.experience * 100 / this.maxExperience;
	}

	public Coordinate getCoord() {
		return coord;
	}

	public void setCoord(Coordinate coord) {
		this.coord = coord;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public boolean isReady() {
		return ready;
	}

	public void setReady(boolean ready) {
		this.ready = ready;
	}

	public int getExperience() {
		return experience;
	}

	public boolean setExperience(int experience) {
		boolean result = false;
		this.experience = experience;
		if(this.experience > maxExperience) {
			result = true;
			calcMaxExperience();
			this.level++;
			this.experience = 0;
		}
		calcPercentExperience();
		return result;
	}
	
	private void calcMaxExperience() {
		this.maxExperience = (int)((this.level+1)*1.9)*200;
	}

	public List<Item> getListItems() {
		return listItems;
	}

	public void setListItems(List<Item> listItems) {
		this.listItems = listItems;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}
	
	public int getSightRadius() {
		return this.sightRadius;
	}

	public int getCurLevelIndex() {
		return curLevelIndex;
	}

	public void setCurLevelIndex(int curLevelIndex) {
		this.curLevelIndex = curLevelIndex;
	}

	public int getMaxExperience() {
		return this.maxExperience;
	}

	public int getSpriteIndex() {
		return spriteIndex;
	}

	public Item getItemWeapon() {
		return itemWeapon;
	}

	public void setItemWeapon(Item itemWeapon) {
		this.itemWeapon = itemWeapon;
	}

	public Item getItemShield() {
		return itemShield;
	}

	public void setItemShield(Item itemShield) {
		this.itemShield = itemShield;
	}

	public Item getItemHelmet() {
		return itemHelmet;
	}

	public void setItemHelmet(Item itemHelmet) {
		this.itemHelmet = itemHelmet;
	}

	public Item getItemArmor() {
		return itemArmor;
	}

	public void setItemArmor(Item itemArmor) {
		this.itemArmor = itemArmor;
	}

	public int getPercentExperience() {
		return this.percentExperience;
	}
	
	
	
	
	
}
